home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutor.exe
/
ANSWERS
/
CH12_1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-15
|
878b
|
40 lines
#include "stdio.h"
#include "malloc.h"
void main()
{
struct child {
char initial; /* last name initial */
int age; /* childs age */
int grade; /* childs grade in school */
} *boy, *girl;
boy = (struct child *)malloc(sizeof(struct child));
boy->initial = 'R';
boy->age = 15;
boy->grade = 75;
girl = (struct child *)malloc(sizeof(struct child));
girl->age = boy->age - 1; /* she is one year younger */
girl->grade = 82;
girl->initial = 'H';
printf("%c is %d years old and got a grade of %d\n",
girl->initial, girl->age, girl->grade);
printf("%c is %d years old and got a grade of %d\n",
boy->initial, boy->age, boy->grade);
}
/* Result of execution
H is 14 years old and got a grade of 82
R is 15 years old and got a grade of 75
*/